package com.ys.http.network;


import java.io.File;
import java.net.URLConnection;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class Body {

    private final RequestBody body;

    protected Body(RequestBody body) {
        this.body = body;
    }

    public static FormBuilder newFormBody() {
        return FormBuilder.newFormBody();
    }

    public static MultipartBuilder newMultiBody() {
        return MultipartBuilder.newMultipart();
    }

    public static JsonBuilder jsonBody() {
        return JsonBuilder.newBuilder();
    }

    public static RequestBody createFileBody(File file) {
        String type = URLConnection.getFileNameMap().getContentTypeFor(file.getName());
        if (type == null) {
            type = "*/*";
        }
        return createFileBody(file, type);
    }

    public static RequestBody createFileBody(File file, String mimeType) {
        return createFileBody(file, MediaType.parse(mimeType));
    }

    public static RequestBody createFileBody(File file, MediaType type) {
        return RequestBody.create(file, type);
    }

    public RequestBody body() {
        return body;
    }
}
